package com.idemon.springbootrest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
public class SpringBootRestApplication implements CommandLineRunner {

	private Logger log = LoggerFactory.getLogger(this.getClass());

	public static void main(String[] args) {
		SpringApplication.run(SpringBootRestApplication.class, args);
	}

	@Autowired
	private RestTemplateBuilder restTemplateBuilder;

	@Bean
	RestTemplate restTemplate(){
		return restTemplateBuilder.build();
	}

	@Autowired
	private RestTemplate restTemplate;

	@Override
	public void run(String... args) throws Exception {
		String quote = restTemplate.getForObject("https://www.sojson.com/open/api/weather/json.shtml?city=北京", String.class);
		log.info(quote.toString());
		System.exit(0);
	}
}
